package gdepot

import org.junit.runners.Parameterized

enum OrderStatus {TOBEPAID,SHIPPED,CANCELED,SUCCESS,FAILED,RECEIVED,CLOSE}
class Orders {

    Cart cart           //订单对应的购物车
    String receiverName  //收货人姓名
    String address       //收货人地址
    String phone         //收货人电话
    BigDecimal price     //订单总价
    OrderStatus status =    OrderStatus.TOBEPAID   //订单状态
    Date orderDate = new Date()   //下单时间
    Date modifiedDate = new Date()  //订单修改时间
    Date shipDate        //发货时间
    static  belongsTo = [user:User,accountBank:AccountBank]
    static constraints = {
        receiverName(size: 2..10,blank: false)
        phone(matches: /\d{7,11}/,blank: false)
        address(maxSize: 200,blank: false)
        price(min:0.0)
        shipDate(nullable: true)
        accountBank nullable: true
        modifiedDate nullable:true
        cart(validator: {cart->
            if(cart && LineItem.countByCart(cart) >0){
                return true
            }
            return 'blank'
        })

    }

    def beforeUpdate(){
        modifiedDate = new Date()
    }
}
